package com.example.oa;

import javafx.util.converter.ShortStringConverter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.HttpURLConnection;

@WebFilter("/*")
public class PseudoSignInFilter implements Filter {

    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest httpServletRequest = (HttpServletRequest) req;
        HttpServletResponse httpServletResponse = (HttpServletResponse) resp;


        String action = httpServletRequest.getParameter("action");
        if (action != null && action.equals("sign_in")) {
            String referer = httpServletRequest.getHeader("Referer");
            if (!referer.contains("index.jsp")) {
                httpServletRequest.setAttribute("error", "CORS login");
                httpServletRequest.getRequestDispatcher("/index.jsp").forward(req, resp);
            }

        }
        chain.doFilter(req, resp);
    }
}
